package com.spider.dao.hbasefilter;

import java.util.List;

import org.apache.hadoop.hbase.Cell;
import org.apache.hadoop.hbase.CellUtil;
import org.apache.hadoop.hbase.client.Result;
import org.apache.hadoop.hbase.util.Bytes;

public class HBaseFilterTest {
	public static void main(String[] args) throws Exception {
		HBaseFilter hbf = new HBaseFilterImp();
		String tableName = "Test";
		int rowCount = 0;
		List<Result> list = hbf.ColumnPaginationFilter(tableName, 2, 1);
		for (Result rs : list) {
			System.out.println(rs);
		}

		list = hbf.ColumnPrefixFilter(tableName, "g");
		for (Result rs : list) {
			System.out.println(rs);
		}

		list = hbf.ColumnRangeFilter(tableName, "answerUrl", true, "diff", false, "1", "10000");
		for (Result rs : list) {
			System.out.println(rs);
		}

		list = hbf.FirstKeyOnlyFilter(tableName);
		for (Result rs : list) {
			Cell[] rawCells = rs.rawCells();
			for (int i = 0; i < rawCells.length; i++) {
				Cell cell = rawCells[i];
				String qualifier = Bytes.toString(CellUtil.cloneQualifier(cell));
				String value = Bytes.toString(CellUtil.cloneValue(cell));
				System.out.println(qualifier + ":" + value);
				System.out.println("--------------------------");
			}
			rowCount++;
		}
		System.out.println("Total num of rows: " + rowCount);

		list = hbf.RowFilter(tableName, "9999");
		for (Result rs : list) {
			System.out.println(rs);
		}

		list = hbf.PrefixFilter(tableName, "9");
		for (Result rs : list) {
			System.out.println(rs);
		}

		list = hbf.KeyOnlyFilter(tableName);
		for (Result rs : list) {
			System.out.println(rs);
		}

		list = hbf.RandomRowFilter(tableName, 0.5f);
		for (Result rs : list) {
			System.out.println(rs);
		}

		list = hbf.ValueFilter("Test", "����");
		for (Result rs : list) {
			System.out.println(rs);
			Cell[] rawCells = rs.rawCells();
			for (int i = 0; i < rawCells.length; i++) {
				Cell cell = rawCells[i];
				String qualifier = Bytes.toString(CellUtil.cloneQualifier(cell));
				String value = Bytes.toString(CellUtil.cloneValue(cell));
				System.out.println(qualifier + ":" + value);
				System.out.println("--------------------------");
			}
		}
	}
}
